<template>

<div id="AgentMenu">
  <div id="homeBar">
    <mu-appbar title="代理详情" style="background-color:#409EFF">
      <mu-icon-button  icon="arrow_back_ios" slot="left" :to="{name: 'Home' }"/>
    </mu-appbar>
  </div>

  <mu-list>
    <mu-list-item title="" :to="{name: 'NewAgentDetail' }">
      <mu-avatar v-bind:src="this.$image.icon1" slot="leftAvatar"/>
      <div class="mu-item-title">今日新增代理<span style="color:red">&nbsp;{{ this.newAgent}}</span></div>
      <mu-icon value="arrow_forward"  slot="right"/>
    </mu-list-item>
    <mu-list-item title="" :to="{name: 'AgentDetail' }">
      <mu-avatar v-bind:src="this.$image.icon2" slot="leftAvatar"/>
      <div class="mu-item-title">代理总人数<span style="color:red">&nbsp;{{ this.totalAgent }}</span></div>
      <mu-icon value="arrow_forward" slot="right"/>
    </mu-list-item>
  </mu-list>
</div>

</template>

<script>


export default {
  data () {
    return {
      newAgent: 0,
      totalAgent: 0,
      isAdmin: false,
      condition: {
        startDay: this.$time.getDateBefore(new Date(), 0),
        endDay: this.$time.getDateBefore(new Date(), 0),
        account: sessionStorage.getItem('account')
      }
    }
  },
  methods: {
    getNewAgentNumber () {
      let that = this
      this.$axios({
        method: 'get',
        url: '/api/AgentService.getNewAgentNumber',
        params: this.condition
      })
      .then(function (resp) {
        that.newAgent = resp.data.data
      })
    },
    getAgentNum () {
      let that = this
      this.$axios({
        method: 'get',
        url: '/api/AgentService.getAgentNum',
        params: {'account': sessionStorage.getItem('account')}
      })
      .then(function (resp) {
        that.totalAgent = resp.data.data
      })
    }
  },
  mounted () {
    if (sessionStorage.getItem('role') === 'admin') {
      this.isAdmin = true
    }
    this.getNewAgentNumber()
    this.getAgentNum()
  }
}
</script>
